package com.chq.version;

import com.chq.version.util.FileUtil;
import com.chq.version.util.PropertiesUtil;
import com.chq.version.util.SVNUtil;
import com.chq.version.util.ZipUtil;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.io.SVNRepository;

import java.util.Map;

public class SVNTest {

    public static void main(String[] args) {

        SVNUtil.initSVNService();
        //加载配置文件
        Map<String, String> map = PropertiesUtil.getMap("conn");
        //获取版本号
        long revision = Long.parseLong(map.get("svn.revision"));
        //项目路径
        String itemsPath = map.get("path.items");
        //临时存储路径
        String tempPath = map.get("path.temp");
        //压缩包打包路径
        String zipPath = map.get("path.zip");

        //连接SVN
        SVNRepository repository = SVNUtil.getSVNRepository(map.get("svn.url"), map.get("svn.username"),
                map.get("svn.password"));

        //SVN最后版本
        long latestRevision = -1;
        try {
            latestRevision = SVNUtil.getLatestRevision(repository);
        } catch (SVNException svne) {
            svne.printStackTrace();
        }
        try {
            FileUtil.delFilePath(tempPath);
            SVNUtil.copyCodeToDestPath(repository, revision, tempPath, itemsPath);
            //删除历史文件
            FileUtil.delFilePath(zipPath + latestRevision + ".zip");
            //生成压缩包
            ZipUtil.zip(tempPath, zipPath, "es_v1.0.0." + revision + "_" + latestRevision + ".zip");
            System.out.println("打包成功！");
            Runtime.getRuntime().exec("cmd /c start "+zipPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
